#coding:utf-8
def get_md5(str):
    #MD5+Base64加密
    import hashlib
    import base64
    md5 = hashlib.md5()
    md5.update(str.decode('UTF-8'))
    src_val = md5.digest()
    b64_val = base64.b64encode(src_val)
    return b64_val

def get_urlen(d):
    #ULR编码
    import urllib
    return urllib.urlencode({"name":d})

def get_urlen_value(d):
    urlen_val = {}
    for k,v in d.items():
        result = get_urlen(v)
        urlen_val[k]="".join(result.split("name=")).strip()
    return urlen_val

def main(xml_data,secretKey):
    t = get_md5(xml_data + secretKey)
    d = {}
    d['logistics_interface']=xml_data
    d['data_digest'] = t
    t1 = get_urlen_value(d)
    #print qupte()  
    return  t1

    

if __name__ =="__main__":
    
    secretKey="ea8fee9dbd844e2b82a4cb42dea2d091"
    xml_data = "<ItemInfoQueryRequestDown><checkword>01f18980363f40e48416464baf4cc7c0</checkword>\
<serialNumber>00001</serialNumber>\
<warehouseCompanyCode>ALOG</warehouseCompanyCode>\
<companyCode>LCSFPZ</companyCode>\
<pageIndex>1</pageIndex><itemCodeList><itemCode>\
</itemCode></itemCodeList></ItemInfoQueryRequestDown>"
    #print get_md5(secretKey)
    print main(xml_data,secretKey)
    






"""
['data_digest: 7eva%2FWU9u9JY%2FXP4UFOi%2FA%3D%3D',
'logistics_interface: %3CItemInfoQueryRequestDown%3E%3Ccheckword%3Echeckword%3C%2Fcheckword%3E%3CserialNumber%3E00001%3C%2FserialNumber%3E%3CwarehouseCompanyCode%3ELCSFPZ%3C%2FwarehouseCompanyCode%3E%3CcompanyCode%3EALOG%3C%2FcompanyCode%3E%3CpageIndex%3E1%3C%2FpageIndex%3E%3CitemCodeList%3E%3CitemCode%3E%3C%2FitemCode%3E%3C%2FitemCodeList%3E%3C%2FItemInfoQueryRequestDown%3E']
"""

    

